using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using AudioDjStudio;

namespace IntelliTouchMix
{
	public partial class FormEqualizerA : Form
	{
		public FormEqualizerA()
		{
			InitializeComponent();
		}

		AxSLIDERLib.AxGSlider[] m_tableSliders = new AxSLIDERLib.AxGSlider[10];
		Int32[] m_tableFrequencies = new Int32[10];

		public FormMain frmMain;

		const int DSFXPARAMEQ_GAIN_MIN = -15;
		const int DSFXPARAMEQ_GAIN_MAX = 15;

		private void FormEqualizerA_Load(object sender, EventArgs e)
		{
			m_tableSliders[0] = GSlider_Equal_0;
			m_tableSliders[1] = GSlider_Equal_1;
			m_tableSliders[2] = GSlider_Equal_2;
			m_tableSliders[3] = GSlider_Equal_3;
			m_tableSliders[4] = GSlider_Equal_4;
			m_tableSliders[5] = GSlider_Equal_5;
			m_tableSliders[6] = GSlider_Equal_6;
			m_tableSliders[7] = GSlider_Equal_7;
			m_tableSliders[8] = GSlider_Equal_8;
			m_tableSliders[9] = GSlider_Equal_9;

			bool	bDirectX8Avail = frmMain.audioDjStudio1.IsDirectX8Available ();
			if (!bDirectX8Avail)
			{
				CheckEnableEQ.Text = "Not available";
				CheckEnableEQ.Enabled = false;
				for (int i = 0; i <= 9; i++)
					m_tableSliders[i].Enabled = false;
			}

			for (int i = 0; i <= 9; i++)
			{
				m_tableSliders[i].Min = DSFXPARAMEQ_GAIN_MIN;
				m_tableSliders[i].Max = DSFXPARAMEQ_GAIN_MAX;
				m_tableSliders[i].TicStart = DSFXPARAMEQ_GAIN_MIN;
				m_tableSliders[i].TicStop = DSFXPARAMEQ_GAIN_MAX;
				m_tableSliders[i].TicDelta = 2;
			}

			m_tableFrequencies[0] = 100;
			m_tableFrequencies[1] = 300;
			m_tableFrequencies[2] = 400;
			m_tableFrequencies[3] = 1500;
			m_tableFrequencies[4] = 2500;
			m_tableFrequencies[5] = 4300;
			m_tableFrequencies[6] = 6000;
			m_tableFrequencies[7] = 8000;
			m_tableFrequencies[8] = 12000;
			m_tableFrequencies[9] = 15000;
		}

		private void GSlider_Equal_0_Slide(object sender, EventArgs e)
		{
			frmMain.audioDjStudio1.EqualizerBandSetGain(frmMain.DECKA_PLAYER, m_tableFrequencies[0], (float) GSlider_Equal_0.Value);
		}

		private void GSlider_Equal_1_Slide(object sender, EventArgs e)
		{
			frmMain.audioDjStudio1.EqualizerBandSetGain(frmMain.DECKA_PLAYER, m_tableFrequencies[1], (float)GSlider_Equal_1.Value);
		}

		private void GSlider_Equal_2_Slide(object sender, EventArgs e)
		{
			frmMain.audioDjStudio1.EqualizerBandSetGain(frmMain.DECKA_PLAYER, m_tableFrequencies[2], (float)GSlider_Equal_2.Value);
		}

		private void GSlider_Equal_3_Slide(object sender, EventArgs e)
		{
			frmMain.audioDjStudio1.EqualizerBandSetGain(frmMain.DECKA_PLAYER, m_tableFrequencies[3], (float)GSlider_Equal_3.Value);
		}

		private void GSlider_Equal_4_Slide(object sender, EventArgs e)
		{
			frmMain.audioDjStudio1.EqualizerBandSetGain(frmMain.DECKA_PLAYER, m_tableFrequencies[4], (float)GSlider_Equal_4.Value);
		}

		private void GSlider_Equal_5_Slide(object sender, EventArgs e)
		{
			frmMain.audioDjStudio1.EqualizerBandSetGain(frmMain.DECKA_PLAYER, m_tableFrequencies[5], (float)GSlider_Equal_5.Value);
		}

		private void GSlider_Equal_6_Slide(object sender, EventArgs e)
		{
			frmMain.audioDjStudio1.EqualizerBandSetGain(frmMain.DECKA_PLAYER, m_tableFrequencies[6], (float)GSlider_Equal_6.Value);
		}

		private void GSlider_Equal_7_Slide(object sender, EventArgs e)
		{
			frmMain.audioDjStudio1.EqualizerBandSetGain(frmMain.DECKA_PLAYER, m_tableFrequencies[7], (float)GSlider_Equal_7.Value);
		}

		private void GSlider_Equal_8_Slide(object sender, EventArgs e)
		{
			frmMain.audioDjStudio1.EqualizerBandSetGain(frmMain.DECKA_PLAYER, m_tableFrequencies[8], (float)GSlider_Equal_8.Value);
		}

		private void GSlider_Equal_9_Slide(object sender, EventArgs e)
		{
			frmMain.audioDjStudio1.EqualizerBandSetGain(frmMain.DECKA_PLAYER, m_tableFrequencies[9], (float)GSlider_Equal_9.Value);
		}

		private void CheckEnableEQ_CheckedChanged(object sender, EventArgs e)
		{
			if (CheckEnableEQ.Checked)
			{
				// check if equalizer bands have already been set for this player
				int nBands = frmMain.audioDjStudio1.EqualizerBandGetCount(frmMain.DECKA_PLAYER);
				if (nBands == 0)
				{
					// add equalizer bands to the player
					for (int i = 0; i <= 9; i++)
						frmMain.audioDjStudio1.EqualizerBandAdd(frmMain.DECKA_PLAYER, m_tableFrequencies[i], 12, (float)m_tableSliders[i].Value);
				}
				// enable the equalizer
				frmMain.audioDjStudio1.EqualizerEnable(frmMain.DECKA_PLAYER, true);
			}
			else
				// disable the equalizer
				frmMain.audioDjStudio1.EqualizerEnable(frmMain.DECKA_PLAYER, false);
		}

		private void BtnReset_Click(object sender, EventArgs e)
		{
			for (int i = 0; i <= 9; i++)
			{
				m_tableSliders[i].Value = 0;
				frmMain.audioDjStudio1.EqualizerBandSetGain(frmMain.DECKA_PLAYER, m_tableFrequencies[i], (float)m_tableSliders[i].Value);
			}
		}
	}
}